package com.zl.learning.bigdata.druid;

import org.junit.Test;

import java.sql.*;

public class DruidTest {

    public Connection getConn() throws SQLException {
        return DriverManager.getConnection("jdbc:avatica:remote:url=http://172.31.4.241:8082/druid/v2/sql/avatica/");
    }

    @Test
    public void test1() {

        try (Connection conn = getConn()) {
            long start = System.currentTimeMillis();
//            String sql = "SELECT * from hotspot limit 400";
            String sql = "select imsi personId, __time captureTime,deviceid deviceId from hotspot WHERE __time BETWEEN '2019-01-18 00:00:00' and '2019-01-22 00:00:00' and deviceid in ('2019117','2019132','2019118','2019133','2019119','2019131','2019116','2019111','2019110','2019100','2019101','2019106','2019107','2019120','2019121','2019125','2019108','2019109','2019122','2019103','2019104','2019102','2019105','2019123','2019112','2019113','2019114','2019115') ";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery();
            int count = 0;
//            rs.absolute(399900);
//            rs.setFetchSize(40000);  //const:153854
//            rs.setFetchSize(10000); //const:59724
            rs.setFetchSize(5000); //const:141101
            System.out.println(rs.getFetchSize());
            while (rs.next()) {
                count++;
//                ResultSetMetaData metaData = rs.getMetaData();
//                metaData.getColumnType()
//                System.out.println(rs.getString("imsi"));
                if (count > 39900) {
                    System.out.println(rs.getString("personId"));
                }
            }
            System.out.println(count);
            long end = System.currentTimeMillis();
            System.out.println("const:" + (end - start));
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
